﻿using Dexter.Scheduler;
using Dexter.Services;

namespace Dexter.Jobs.Statistics {
	/// <summary>
	/// This class must update the blog statistics
	/// </summary>
	public class StatisticsJob : ICronJob {
		readonly ICategoryService categoryService;

		/// <summary>
		/// Initializes a new instance of the <see cref="T:System.Object"/> class.
		/// </summary>
		public StatisticsJob ( ICategoryService categoryService ) {
			this.categoryService = categoryService;
		}

		/// <summary>
		/// Gets a value indicating whether [auto manage session].
		/// </summary>
		/// <value><c>true</c> if [auto manage session]; otherwise, <c>false</c>.</value>
		public bool AutoManageSession {
			get { return true; }
		}

		/// <summary>
		/// Gets the name of the group.
		/// </summary>
		/// <value>The name of the group.</value>
		public string GroupName {
			get { return null; }
		}

		/// <summary>
		/// Set to <c>false</c> if the state of Job will be reused from the next startup. Otherwise <c>false</c>.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is volatile; otherwise, <c>false</c>.
		/// </value>
		public bool IsVolatile {
			get { return true; }
		}

		/// <summary>
		///This method will be exececuted by the <see cref="IScheduler"/>
		/// </summary>
		/// <remarks>
		///	The execution interval depends by <see cref="ICronJob"/> or <see cref="IFrequentlyJob"/>.
		/// </remarks>
		public void Execute ( ) {
			categoryService.UpdateCategoryStatistics ( );
		}

		/// <summary>
		/// Gets the unique id.
		/// </summary>
		/// <value>The unique id.</value>
		public string UniqueId {
			get { return "{d3a66a17-92f1-4398-a41e-e23a4f7b7f8a}"; }
		}

		/// <summary>
		/// The Cron pattern.
		/// </summary>
		/// <remarks>
		///		See this documentation http://en.wikipedia.org/wiki/Cron or use this tool http://www.cronmaker.com/ .
		/// </remarks>
		/// <value>The cron patter.</value>
		public string CronPatter {
			get {
				return "0 2 2 1/1 * ? *";
			}
		}
	}
}
